package com.hyf.serviceedu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyf.commonutils.fruit;
import com.hyf.serviceedu.entity.EduCourse;
import com.hyf.serviceedu.entity.EduTeacher;
import com.hyf.serviceedu.service.EduCourseService;
import com.hyf.serviceedu.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description="前台页面显示")
@RestController
@RequestMapping("serviceedu/indexfront")
//@CrossOrigin
public class IndexFrontController {

    //分别注入课程和讲师的service
    @Autowired
    private EduCourseService eduCourseService;

    // 注入讲师的service
    @Autowired
    private EduTeacherService eduTeacherService;

    //查询前八条热门课程。查询前四名讲师
    @ApiOperation(value = "查询前四名讲师")
    @GetMapping("index")
    public fruit index(){

        //查询钱8条热门课程的信息
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        // 写入条件
        wrapper.orderByDesc("id");// 根据id 进行排序
        wrapper.last("limit 8");// 查询钱8条记录

        List<EduCourse> eduCourseList = eduCourseService.list(wrapper);// 调用方法查询前8条记录

        // 查询教师的前四条记录
        QueryWrapper<EduTeacher> teacherQueryWrapper=new QueryWrapper<>();
        // 写入条件
        teacherQueryWrapper.orderByDesc("id");// 根据id 进行查询
        teacherQueryWrapper.last("limit 4");// 查询钱4 条记录

        // 调用方法
        List<EduTeacher> eduTeachers = eduTeacherService.list(teacherQueryWrapper);

        return fruit.ok().data("eduCourseList",eduCourseList).data("eduTeachers",eduTeachers);// 最后把值返回一下
    }






/*
  课件中的方法

    //查询前8条热门课程，查询前4条名师
    @GetMapping("index")
    public fruit index() {
        //查询前8条热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> eduList = eduCourseService.list(wrapper);
        //查询前4条名师

        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();

        wrapperTeacher.orderByDesc("id");

        wrapperTeacher.last("limit 4");

        List<EduTeacher> teacherList = eduTeacherService.list(wrapperTeacher);

        return fruit.ok().data("eduList",eduList).data("teacherList",teacherList);

    }*/

}
